package com.home.zqt.platform.controller;

import com.home.zqt.platform.dao.AuthorityDao;
import com.home.zqt.platform.dao.MenuDao;
import com.home.zqt.platform.domain.BaseRequest;
import com.home.zqt.platform.domain.MJAuthority;
import com.home.zqt.platform.domain.MJEnvironmentEnum;
import com.home.zqt.platform.domain.MJMenu;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author soon
 * @description: TODO
 * @date 2019-06-12 21:41
 **/
@RestController("menuController")
public class MenuController {

    @Autowired
    private MenuDao menuDao;
    @Autowired
    private AuthorityDao authorityDao;

    @GetMapping("/menu/list-all")
    public List<MJMenu> findAllMenuList() {
        return menuDao.findAll();
    }

    /**
     * 获取根菜单
     *
     * @return
     */
    @GetMapping("/menu/list-root")
    public List<MJMenu> findMenuRootList() {
        return menuDao.findRootList();
    }

    /**
     * 获取指定菜单所有下级菜单列表
     *
     * @param request
     * @return
     */
    @GetMapping("/menu/list-children")
    public List<MJMenu> findMenuChildrenList(BaseRequest request) {
        MJMenu condition = new MJMenu();
        condition.setId(request.getMenuId());
        return menuDao.findChildrenList(condition);
    }

    /**
     * 添加菜单
     *
     * @param request
     * @param menu
     * @return
     * @throws Exception
     */
    @PostMapping("/menu")
    public MJMenu createMenu(@RequestParam List<MJEnvironmentEnum> envList, @RequestBody MJMenu menu) throws Exception {
        menuDao.create(envList, menu);
        return menu;
    }

    /**
     * 关联菜单-接口权限
     *
     * @param request
     * @return
     */
    @PutMapping("/menu/authority/add")
    public List<MJAuthority> addMenuAuthorityList(BaseRequest request) {

        return null;
    }

    /**
     * 删除菜单-接口权限
     *
     * @param request
     */
    @PutMapping("/menu/authority/remove")
    public void removeMenuAuthorityList(BaseRequest request) {

    }

    /**
     * 获取所有接口权限列表
     *
     * @param request
     * @return
     */
    @GetMapping("/authority/list-all")
    public List<MJAuthority> findAuthorityListByCodeOrName(BaseRequest request) {
        return authorityDao.findByCodeOrName(request.getKeyword());
    }

    /**
     * 添加接口权限
     *
     * @param request
     * @param authority
     * @return
     */
    @PostMapping("/authority")
    public MJAuthority createAuthority(BaseRequest request, @RequestBody MJAuthority authority) {

        return null;
    }
}
